//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#ifndef __TESTING_ASM_H__
#define __TESTING_ASM_H__

#include <testing/tp_slot.h>

EXTERN_C inline void __cdecl GetCycleCount(TIMESTAMP * pTsp, int bReset = 0)
{
    ASM("rdtsc"
        :"=a" (pTsp->low),
         "=d" (pTsp->high));
}

EXTERN_C inline void timepeg_stamp(TIMESTAMP *pstamp, int bReset = 0)
{
    GetCycleCount(pstamp, bReset);
}

/*add two timepegs*/
inline void timepeg_add(TIMESTAMP* padd, TIMESTAMP* pacc)
{
    ASM("addl %2, %0\n\t"
        "adcl %3, %1\n\t"
        : "=r" (pacc->low), "=r" (pacc->high)
        : "g" (padd->low), "g" (padd->high),
        "0" (pacc->low), "1" (pacc->high));
}
/*sub two timepegs*/
inline void timepeg_sub(TIMESTAMP* psub, TIMESTAMP* pacc)
{
    ASM("subl %2, %0\n\t"
        "sbbl %3, %1\n\t"
        : "=r" (pacc->low), "=r" (pacc->high)
        : "g" (psub->low), "g" (psub->high),
        "0" (pacc->low), "1" (pacc->high));
}

EXTERN_C void timepeg_asm();

#define TIMEPEG_ASM(_M_name)  \
    do { \
        ASM("call   _timepeg_asm;");\
    } while (0);

#endif
